<?php
$host = "0.0.0.0";
$port = 9501;

$server = new swoole_websocket_server($host, $port);
$settings = [
    'worker_num'  => 8,
    'daemonize'   => false, //是否作为守护进程,此配置一般配合log_file使用
    'max_request' => 1000,
    'log_file'    => './swoole.log',
    'task_worker_num' => 8
];
$server->set($settings);
$server->on('open', function (swoole_websocket_server $server, $request) {
    echo "server: handshake success with fd{$request->fd}\n";
    $server->push($request->fd, "连接成功了啊");
});

$server->on('message', function(swoole_websocket_server $server,$request){
    $server->task(json_encode($server));
    $server->push($request->fd, "你点击的屏幕坐标是$request->data");
});

$server->on('close', function($server,$fd){
    echo "client {$fd} closed\n";
});

$server->on('task', function($server, $task_id, $from_id, $data){
    var_dump(json_decode($data));
    echo $task_id."\n".$from_id;
    return true;
});

$server->on('finish', function($server,$task_id, $data) {
    echo "完成任务\n";
});

$server->start();